package lesson2.com.animals;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Zoo {
    
    
    private List animals = new ArrayList();
    
    public void addAnimal(Animal a){
        animals.add(a);
    }
    
    public void removeAnimal(Animal a){
        animals.add(a);
    }
    
    public Animal getAnimalByIndex(int index){
        return (Animal)animals.get(index);
    }
    
    public List getAnimalsList(){
        return Collections.unmodifiableList(this.animals);
    }
    
    
    
    public static void main(String[] args){
        Lion leo = new Lion("Leo"); //<< one Lion object, "leo" knows all about Lions
        leo.walk();
       // leo.roar();
        
        Feline anotherLion= new Lion("Leo");  //<< anotherLion is even less dumb than anAnimal
       // anotherLion.walk();
        
        Animal anAnimal = leo; // << slightly smarter than "obj" below
        String s = anAnimal.toString();
        s = leo.toString();
        s = anotherLion.toString();
      /*  
        Object obj = leo;  // this is the "dumbest" reference
        s = obj.toString();
        
        System.out.println("leo.getName() produces "+leo.getName());
        System.out.println("((Lion)anotherLion).getName() produces "+((Lion)anotherLion).getName() );
        
        if(leo==anotherLion){
            System.out.println("leo is referencing SAME object as anotherLion references");
        }else {
            System.out.println("leo and anotherLion reference DIFFERENT object instances");
        }
        
        if(leo.equals(anotherLion)){
            System.out.println("using leo.equals(anotherLion) produces true");
        }else{
            System.out.println("using leo.equals(anotherLion) produces false");
        }
        
        Banana ban = new Banana();
        boolean boo = leo.equals(ban);
        System.out.println("Is leo equal to ban? "+boo);
        
        if(ban instanceof Object){  //<< will ALWAYS be true
            
        }
        */
        
        SerenghettiLion wildBoy = new SerenghettiLion();
        System.out.println(wildBoy.getName());
        
        wildBoy = new SerenghettiLion("scarey guy");
        System.out.println(wildBoy.getName());
        
        //Animal a = new Animal(); // compiler error because Animals can not be instantiated
        Animal a = new Spider();
        a.walk();
        
        FlyingSquirrel rocky = new FlyingSquirrel();
        rocky.someMethod(0);
        
        System.out.println("----------------");
        
        Zoo myZoo = new Zoo();
        myZoo.addAnimal(rocky);
        myZoo.addAnimal(leo);
        myZoo.addAnimal(a);
        
        List theFamily = myZoo.getAnimalsList();
        for(Object obj: theFamily){
            a = (Animal)obj;
            a.walk();
        }
        
    }

}

class Banana {}

